<!--
 * Tencent is pleased to support the open source community by making Tars available.
 *
 * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
 *
 * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * https://opensource.org/licenses/BSD-3-Clause
 *
 * Unless required by applicable law or agreed to in writing, software distributed
 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
-->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>TARS</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/bootstrap_table.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!--[if lt IE 9]>
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script src="../js/jquery.min.js"></script>
    <script src="../js/bootstrap.min.js"></script>
    <script src="../js/bootstrap_table.min.js"></script>
    <script src="../js/template.js"></script>
    <script src="../js/common.js"></script>
    <script src="../js/service_cfg.js?v=2016122901"></script>
</head>
<body>

<div class="table-box">
    <h4 class="sub-header">配置列表</h4>
    <div class="tool-bar">
        <button type="button" class="btn btn-sm btn-primary" onclick="addCfg()">添加配置</button>
    </div>
    <div id="cfg-box" class="mt10">
    </div>
    <div id="ref-container" style="display: none">
        <h4 class="sub-header">引用文件列表</h4>
        <div class="tool-bar">
            <button type="button" class="btn btn-sm btn-primary" onclick="addCfgRef()">添加引用文件</button>
        </div>
        <div id="file-box" class="mt10">
        </div>
    </div>
    <div id="node-container" style="display: none">
        <h4 class="sub-header">节点配置列表</h4>
        <div class="tool-bar">
            <button type="button" class="btn btn-primary btn-sm" id="push-btn">PUSH配置文件</button>
        </div>
        <div id="node-box" class="mt10">
        </div>
    </div>
</div>

<div id="dlg-add-cfg" class="form-horizontal" style="display: none">
    <div id="err-msg"></div>
    <div class="form-group">
        <label class="col-sm-2 control-label">文件名称</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="add-cfg-filename">
            <select name="" class="form-control" id="add-cfg-filename-select" style="display:none"></select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">文件内容</label>
        <div class="col-sm-10">
            <textarea name="" id="add-cfg-filecontent" rows="5" class="form-control"></textarea>
        </div>
    </div>
</div>

<div id="dlg-update-cfg" class="form-horizontal" style="display: none">
    <div id="err-msg2"></div>
    <div class="form-group">
        <label class="col-sm-2 control-label">文件名称</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="update-cfg-filename">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">原因</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="reason">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">文件内容</label>
        <div class="col-sm-10">
            <textarea name="" id="update-cfg-filecontent" rows="5" class="form-control"></textarea>
        </div>
    </div>
</div>

<div id="dlg-ret" class="form-horizontal" style="display:none"></div>

<div id="dlg-history-list" style="display: none;">

</div>

<div id="dlg-file" style="display: none">
    <div class="tool-bar">
        <button type="button" class="btn btn-primary btn-sm" onclick="addCfgRefNode(this)">添加引用文件</button>
    </div>
    <div id="dlg-file-box" class="mt10"></div>
</div>

<div id="dlg-ref-list" class="form-horizontal" style="display: none"></div>


<!--配置文件历史变更记录-->
<script type="text/html" id="cfg-history-tpl">
    <table class="table table-hover table-bordered" id="cfg-history-table">
        <thead>
        <tr>
            <th>时间</th>
            <th>原因</th>
            <th>文件内容</th>
        </tr>
        </thead>
        <tbody>
        {{each data as it}}
        <tr>
            <td>{{it.posttime}}</td>
            <td>{{it.reason}}</td>
            <td><a href="#;" class="viewContent" data-id="{{it.id}}" data-toggle="popover" data-placement="left" title="变更内容">点击查看</a></td>
        </tr>
        {{/each}}
        </tbody>
    </table>
</script>


<script type="text/html" id="cfg-tpl">
    <table class="table table-hover table-bordered" id="cfg-table">
        <thead>
        <tr>
            <th></th>
            <th class="sort">服务名称</th>
            <th>文件名称</th>
            <th>最后修改时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {{each data as it i}}
        <tr class="cfg_row">
            <td class="tc"><label><input type="radio" name="config_id" class="chks" value="{{it.id}}" {{if i==0}}checked{{/if}}></label></td>
            <td>{{it.server_name}}</td>
            <td>{{it.filename}}</td>
            <td>{{it.posttime}}</td>
            <td>
                <a href="#;" onclick="updateCfg({{it.id}},'{{it.filename}}')">修改配置</a> |
                <a href="#;" onclick="deleteCfg({{it.id}})">删除配置</a> |
                <a href="#;" onclick="viewCfg({{it.id}})">查看内容</a> |
                <a href="#;" onclick="viewHistoryCfg({{it.id}})">查看历史</a>
            </td>
        </tr>
        {{/each}}
        </tbody>
    </table>
</script>

<script type="text/html" id="file-tpl">
    <table class="table table-hover table-bordered" id="file-table">
        <thead>
        <tr>
            <th class="sort">服务名称</th>
            <th>节点</th>
            <th>文件名称</th>
            <th>最后修改时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {{each data as it}}
        <tr>
            <td>{{it.reference.server_name}}</td>
            <td>{{it.reference.node_name}}</td>
            <td>{{it.reference.filename}}</td>
            <td>{{it.reference.posttime}}</td>
            <td>
                <a href="#;" onclick="delCfgRef({{it.id}})">删除引用</a> |
                <a href="#;" onclick="viewCfg({{it.reference.id}})">查看引用内容</a> |
                <a href="#;" onclick="viewHistoryCfg({{it.reference.id}})">查看历史</a>
            </td>
        </tr>
        {{/each}}
        </tbody>
    </table>
</script>

<script type="text/html" id="node-tpl">
    <table class="table table-hover table-bordered" id="node-table">
        <thead>
        <tr>
            <th><label><input type="checkbox" onchange="checkAll(this)"></label></th>
            <th class="sort">服务名称</th>
            <th>节点</th>
            <!--<th>设置状态</th>-->
            <!--<th>当前状态</th>-->
            <th>文件名称</th>
            <th>最后修改时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {{each data as it}}
        <tr>
            <td><label><input type="checkbox" class="chks" value="{{it.id}}"></label></td>
            <td>{{it.server_name}}</td>
            <td>{{it.node_name}}</td>
            <!--<td>{{it.cfg_status}}</td>-->
            <!--<td>{{it.curr_status}}</td>-->
            <td>{{it.filename}}</td>
            <td>{{it.posttime}}</td>
            <td>
                <a href="#;" onclick="updateCfg({{it.id}},'{{it.filename}}')">修改配置</a> |
                <a href="#;" onclick="viewMergeCfg({{it.id}})">查看合并后配置</a> |
                <a href="#;" onclick="viewCfg({{it.id}})">查看节点内容</a> |
                <a href="#;" onclick="viewHistoryCfg({{it.id}})">查看历史</a> |
                <a href="#;" onclick="manageRefCfg({{it.id}})">管理引用文件</a>
            </td>
        </tr>
        {{/each}}
        </tbody>
    </table>
</script>
</body>
</html>
